<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="文件名" prop="fileName">
        <el-input
          v-model="queryParams.fileName"
          placeholder="请输入文件名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button v-hasPermi="['information:record:query']" type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="recordList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="文件名" align="center" prop="fileName" />
      <el-table-column label="执行状态(数据字典)" align="center" prop="executionStatus" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.execution_status" :value="scope.row.executionStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="执行时间" align="center" prop="createTime" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            v-if="scope.row.executionStatus === 'EXECUTION_STATUS_3'"
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="openFailureReason(scope.row)"
            v-hasPermi="['information:record:failureReason']"
          >异常原因</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            v-hasPermi="['information:record:download']"
            @click="download(scope.row)"
          >下载</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listRecord } from "@/api/information/record";

export default {
  name: "Record",
  dicts: ['execution_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 选中数组
      ids: [],
      // 总条数
      total: 0,
      // 信息导入记录表格数据
      recordList: [],

      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        fileName: null
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 打开异常原因*/
    openFailureReason(row) {
      this.$alert(row.failureReason, '异常', {
        confirmButtonText: '确定',
        callback: action => {}
      });
    },
    /** 下载*/
    download(row) {
      window.location.href= row.fileUrl
    },
    /** 查询信息导入记录列表 */
    getList() {
      this.loading = true;
      listRecord(this.queryParams).then(response => {
        this.recordList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
  }
};
</script>
